package com.jeff.tianti.org.dao;

import com.jeff.tianti.common.dao.CustomBaseSqlDaoImpl;
import com.jeff.tianti.common.entity.PageModel;
import com.jeff.tianti.org.dto.VolunteerQueryDTO;
import com.jeff.tianti.org.entity.Volunteer;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

public class VolunteerDaoImpl extends CustomBaseSqlDaoImpl implements VolunteerCustomDao {

    @Override
    public PageModel<Volunteer> queryVolunteerPage(VolunteerQueryDTO volunteerQueryDTO) {
        Map<String,Object> params = new HashMap<String,Object>();
        StringBuilder hql = new StringBuilder();
        hql.append(" select r from Volunteer r where 1=1 ");
        if(StringUtils.isNotBlank(volunteerQueryDTO.getName())){
            hql.append(" and r.name like :name ");
            params.put("name", "%"+volunteerQueryDTO.getName()+"%");
        }

        if(StringUtils.isNotBlank(volunteerQueryDTO.getIdentityCard())){
            hql.append(" and r.identity_card = :identity_card ");
            params.put("identity_card", volunteerQueryDTO.getIdentityCard());
        }
        hql.append(" order by r.createDate desc ");
        return this.queryForPageWithParams(hql.toString(), params, volunteerQueryDTO.getCurrentPage(), volunteerQueryDTO.getPageSize());
    }
}
